define(['app'],function(app){
    return {module: function($scope, $http, eventBusService, httpService, params) {
        $scope.form = {};

        //学段列表
        httpService.post(app.urls.stage_selectAll, {}, function (data) {
            if ("0000" === data.code) {
                $scope.stageList = data.data;
            } else {
                alert(data.msg);
            }
        });

        //学科列表
        var getSubjectList = function() {
            httpService.post(app.urls.subject_selectByStage, {"fk_stage" : $scope.form.fk_stage}, function (data) {
                if ("0000" === data.code) {
                    $scope.subjectList = data.data;
                } else {
                    alert(data.msg);
                }
            });
        }

        //学段选择改变
        $scope.selectStageChange = function() {
            getSubjectList();
        }

        //教材信息
        httpService.post(app.urls.version_selectById, {"id" : params.id}, function(data){
            if("0000" === data.code){
                $scope.form = data.data;
                getSubjectList();
            }else{
                alert(data.msg);
            }
        });


        //保存
        $scope.save = function(){
            if(!$scope.formCheck()){
                return;
            }

            httpService.post(app.urls.version_update, $scope.form, function(data){
                if("0000" === data.code){
                    eventBusService.publish("content.page.reload", data.data);
                    eventBusService.publish("modal.page.close",{});
                    
                }else{
                    alert(data.msg);
                }
            });
        }
    }
}});